/*
 * checkheadcrc16.cc
 *
 *  Created on: 2011-1-6
 *      Author: xuhui
 */

#include <click/config.h>
#include "crc.h"
#include "checkheadcrc16.hh"
#include <clicknet/wifi.h>
CLICK_DECLS

CheckHeadCRC16::CheckHeadCRC16(){
	_drops = 0;
}

CheckHeadCRC16::~CheckHeadCRC16(){

}

Packet *
CheckHeadCRC16::simple_action(Packet *p){
	unsigned short crc;

	int len = p->length();
	if(len < 4)
		goto drop;

  crc = update_crc16(0xffff, (char *) p->data(), sizeof(click_wifi));

  unsigned short pcrc;
  memcpy(&pcrc, p->data() + sizeof(click_wifi), 2);
  if(pcrc != crc)
	goto drop;

  return p;

 drop:
  click_chatter("HeadCRC16 failed");
  p->kill();
  _drops++;
  return 0;
}

CLICK_ENDDECLS
EXPORT_ELEMENT(CheckHeadCRC16)
ELEMENT_MT_SAFE(CheckHeadCRC16)
